package com.sjsu.cloudmanager.dao;

import com.sjsu.cloudmanager.model.CloudLab;
import com.sjsu.cloudmanager.model.ComputingMachine;
import com.sjsu.cloudmanager.model.Software;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

/**
 * CloudLab dao
 * User: ckempaiah
 * Date: 9/20/11
 * Time: 12:30 AM
 * To change this template use File | Settings | File Templates.
 */
public class CloudLabDaoImpl extends HibernateDaoSupport implements CloudLabDao{

    @Override
    public Integer createCloudLab(String labName, String status) {
        CloudLab cloudLab = new CloudLab();
        cloudLab.setLabName(labName);
        cloudLab.setLabStatus(status);

        getHibernateTemplate().save(cloudLab);
        return cloudLab.getLabId();
    }

    @Override
    public void saveOrUpdateCloudLab(CloudLab cloudLab) {
        getHibernateTemplate().saveOrUpdate(cloudLab);
    }

    @Override
    public void saveOrUpdate(Object object) {
        getHibernateTemplate().saveOrUpdate(object);
    }

    @Override
    public CloudLab getCloudLab(Integer labId) {

        return getHibernateTemplate().get(CloudLab.class, labId);
    }
    @Override
    public void addComputingMachine(ComputingMachine computingMachine) {
        getHibernateTemplate().saveOrUpdate(computingMachine);
    }

    @Override
    public ComputingMachine getComputingMachine(Integer machineId){
        return getHibernateTemplate().get(ComputingMachine.class, machineId);
    }
    @Override
    public Software getCloudSoftware(Integer softwareId){
        return getHibernateTemplate().get(Software.class, softwareId);
    }

    @Override
    public void removeCloudLab(CloudLab cloudLab) {

        getHibernateTemplate().delete(cloudLab);
    }

    @Override
    public void removeComputingMachine(ComputingMachine computingMachine) {
        getHibernateTemplate().delete(computingMachine);
    }
}
